package com.zmn.plat.admin.controller.funswitch;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.GlobalDict;
import com.zmn.plat.model.entity.funswitch.PublicBaseCodeMap;
import com.zmn.plat.model.entity.funswitch.PublicBaseCodeMapQuery;

/**
 * 公共基础配置管理查看相关处理
 * 
 * @author hedaiping
 * @create 2019/03/25/11:16
 */
@Controller
@RequestMapping("/funswitch")
public class FunctionListController extends FunctionBaseController {

    /**
     * 分页展示码表信息
     * 
     * @param baseCodeMapQuery
     * @return
     */
    @RequiresPermissions("/funswitch/list.action")
    @RequestMapping("/list.action")
    public ModelAndView listCodeMapByPage(@ModelAttribute PublicBaseCodeMapQuery baseCodeMapQuery) {

        List<PublicBaseCodeMap> baseCodeMaps = baseCodeMapService.listPageByQuery(baseCodeMapQuery);

        ModelAndView mav = new ModelAndView("funswitch/list");
        mav.addObject("items", baseCodeMaps);
        mav.addObject("vo", baseCodeMapQuery);
        mav.addObject("statuses", GlobalDict.getStatusList(false));
        return mav;

    }

    /**
     *
     * @param mapId
     *            0表示新创建
     * @return
     */
    @RequiresPermissions("/funswitch/detail.action")
    @RequestMapping("/detail")
    public ModelAndView detailCodeMap(@RequestParam(value = "mapId", defaultValue = "0") int mapId) {

        PublicBaseCodeMap codeMap;
        if (mapId == 0) {
            codeMap = new PublicBaseCodeMap();
        } else {
            codeMap = baseCodeMapService.findByKey(mapId);
        }

        ModelAndView mav = new ModelAndView("funswitch/detail");
        mav.addObject("codeMap", codeMap);
        mav.addObject("statuses", GlobalDict.getStatusList(false));
        mav.addObject("plats", GlobalConsts.getPlatList());
        return mav;
    }

}
